﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Insteon.Messages.Insteon;

namespace Insteon.Commands.Insteon
{
    internal class AllLinkCommand : Command
    {

        internal readonly byte Command;
        internal readonly byte Group;

        internal AllLinkCommand(byte Group, byte Command)
        {
            this.Command = Command;
            this.Group = Group;

            buffer = new byte[5];
            buffer[0] = 0x02;
            buffer[1] = 0x61;
            buffer[2] = Group;
            buffer[3] = Command;
            buffer[4] = Group;
        }

        internal override bool IsResponse(Messages.Message Message)
        {
            if (!(Message is Messages.Insteon.AllLinkResponse))
            {
                return false;
            }
            AllLinkResponse Response = (AllLinkResponse)Message;
            if ((Response.Group == this.Group) && (Response.Command == this.Command))
            {
                ModemCompleted = true;
                ModemResponse = Message;
                if (Response.Status.Status == ResponseStatus.Statuses.ACK)
                {
                    this.Succeed();
                }
                else
                {
                    this.Fail();
                }
                return true;
            }
            return false;
        }
    }
}
